woogc/ps/synchronize_product/origin_product/meta_data
Name: woogc/ps/synchronize_product/origin_product/meta_data
Type: Filter
Arguments: $args
Filter being used to modify the product synchronization data before it is sent from the origin shop to the destination shop.
The filter is applied to the $args array immediately before the synchronization request is made. The $args array contains the product object, product metadata, product type, attributes, images, synchronization arguments, origin shop ID, and origin product ID.
The product_meta property can be modified to add, change, or remove custom product metadata that will be available during the synchronization process.
The following sample code snippets demonstrate common scenarios, including adding custom product metadata, adding the origin site’s WooCommerce currency to the synchronization data, and modifying an existing product meta value.
Sample Usage
Add the origin site’s WooCommerce currency to the product metadata:
add_filter( 'woogc/ps/synchronize_product/origin_product/meta_data', 'my_woogc_add_site_currency', 10, 1 );
function my_woogc_add_site_currency( $args )
{
$args['product_meta']['_origin_product_currency'][] = get_option( 'woocommerce_currency' );
return $args;
}
This adds a custom _origin_product_currency property to product_meta, containing the currency configured on the origin WooCommerce site.
For example, if the origin site uses EUR:
$args['product_meta']['_origin_product_currency'] = 'EUR';
If the origin site uses USD:
$args['product_meta']['_origin_product_currency'] = 'USD';
Add custom product metadata from the origin product:
add_filter( 'woogc/ps/synchronize_product/origin_product/meta_data', 'my_woogc_add_custom_product_meta', 10, 1 );
function my_woogc_add_custom_product_meta( $args )
{
$supplier_reference = get_post_meta(
$args['origin_product_id'],
'_supplier_reference',
TRUE
);
if ( ! empty( $supplier_reference ) )
$args['product_meta']['_supplier_reference'] = $supplier_reference;
return $args;
}
The _supplier_reference custom property is retrieved from the origin product and added to the product_meta array.
Modify an existing product meta value:
add_filter( 'woogc/ps/synchronize_product/origin_product/meta_data', 'my_woogc_modify_product_meta', 10, 1 );
function my_woogc_modify_product_meta( $args )
{
if ( isset( $args['product_meta']['_custom_value'] ) )
$args['product_meta']['_custom_value'] =
'prefix-' . $args['product_meta']['_custom_value'];
return $args;
}
Using a class method instead of a standalone function:
class My_Woogc_Sync_Customizations {
public function __construct() {
add_filter(
'woogc/ps/synchronize_product/origin_product/meta_data',
array( $this, 'add_site_currency' ),
10,
1
);
}
public function add_site_currency( $args ) {
$args['product_meta']['_origin_product_currency'] =
get_option( 'woocommerce_currency' );
return $args;
}
}
new My_Woogc_Sync_Customizations();

No Comments